//------------------------------------------------------------------------------
#include <QMessageBox>
#include "CComboResultFrm.h"
#include "CSelectArticleFrm.h"
#include "CMySQL.h"
//------------------------------------------------------------------------------
CSelectArticleFrm::CSelectArticleFrm(QWidget *parent) : QDialog(parent) {
	setupUi(this);
	
	cbArticle->setFocus();
}
//------------------------------------------------------------------------------
void CSelectArticleFrm::on_cbArticle_clicked(CMyComboBox *comboBox) {
	CComboResultFrm *comboResultFrm=new CComboResultFrm(comboBox->getTableRemp(), comboBox->getChampRemp(), this);
	
	comboResultFrm->setModal(true);
	comboResultFrm->exec();
	
	if(comboResultFrm->result() == QDialog::Accepted) {
		comboBox->setValue(comboResultFrm->getResult());
	}
	
	delete comboResultFrm;
}
//------------------------------------------------------------------------------
void CSelectArticleFrm::accept(void) {
	if(CMySQL::getInstance()->existe(cbArticle->getTableRemp(), cbArticle->getChampRemp(), cbArticle->getValue())) {
		QDialog::accept();
	}else {
		QMessageBox msgBox(	QMessageBox::Warning, tr("Attention"), 
							tr("Attention, l'article ")+cbArticle->getValue()+tr(" n'existe pas"),
							QMessageBox::Ok);
		msgBox.exec();
	}
}
//------------------------------------------------------------------------------